/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.superme.ResConsumerServiceByribbon.controller;




import com.superme.ResConsumerServiceByribbon.service.TestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class ResourcesHomeController {
	private static final Logger LOGGER = LoggerFactory.getLogger(ResourcesHomeController.class);

	@Autowired
	TestService testService;

	//

	@RequestMapping(value="/hello", method = RequestMethod.GET)
	@ResponseBody
	public String test (OAuth2Authentication oAuth2Authentication) throws Exception {
		//int sleeptime = new Random().nextInt(3000);
		//Thread.sleep(sleeptime);
		if (oAuth2Authentication != null) {
			return testService.test();
		} else {
			return "anonymous";
		}

	}

	@RequestMapping(value = "/log-instance",method = RequestMethod.GET)
	@ResponseBody
	public String logUserInstance(){
		String log  = testService.GetChooseLog();
		ResourcesHomeController.LOGGER.info(log);
		return log;
	}

}
